﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RCP
{
    public partial class frmRCP : Form
    {
        //串口句柄
        int m_hCom = 0;
        //调用DLL返回结果
        int ret = -1;
        public frmRCP()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int Bandrate = 57600;
            if (!"".Equals(this.textBox1.Text))
            {
                m_hCom = int.Parse(this.textBox1.Text);
            }
            if (!"".Equals(this.textBox2.Text))
            {
                Bandrate = int.Parse(this.textBox2.Text);
            }
            ret = (int)RCPClass.RCP11Class.CommOpen(m_hCom, Bandrate);
            if (ret < 1)
            {
                MessageBox.Show("串口打开失败!");
            }
            else
            {
                m_hCom = ret;
                this.button1.Enabled = false;
                this.button2.Enabled = true;
                //MessageBox.Show("串口打开成功!");

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ret = RCPClass.RCP11Class.CommClose(m_hCom);
            if (ret < 1)
            {
                MessageBox.Show("串口关闭失败!");
            }
            else
            {
                this.button1.Enabled = true;
                this.button2.Enabled = false;
                MessageBox.Show("串口关闭成功!");
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            this.richTextBox2.Text = "";
            RCP.RCPClass.CB_RfidCardRequestAndReadData callbackdatastruct;
            byte blocknum = 8;
            byte keymodel = (byte)0x00;
            byte keyval = (byte)0xff;
            byte[] key = new byte[6];
            string callbackdata = "";
            for (int i = 0; i < key.Length; i++)
            {
                key[i] = keyval;
            }
            ret = RCPClass.RCP11Class.RfidCardRequestAndReadData(m_hCom, blocknum, keymodel, key, out callbackdatastruct);

            if (ret == 0)
            {
                callbackdata = "块数据为：";
                byte[] bytestr = new byte[1];
                byte bt = blocknum; //字符型
                byte c = (byte)((bt >> 4) & 0x0F);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + (byte)0x30);
                else
                    c = (byte)(c + (byte)0x37);
                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(bt & 0x0F);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr); //加入接收编辑框对应字符串 
                callbackdata += " ";   //加入接收编辑框对应字符串


                //RCP反馈原始信息
                for (int i = 0; i < 16; i++) //将数组转换为Cstring型变量
                {
                    bt = callbackdatastruct.CallBackData[i]; //字符型

                    c = (byte)((bt >> 4) & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr); //加入接收编辑框对应字符串 

                    c = (byte)(bt & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr); //加入接收编辑框对应字符串 

                    callbackdata += " ";   //加入接收编辑框对应字符串
                }

                this.richTextBox2.Text = callbackdata;
            }
            else
            {
                this.richTextBox2.Text = "读卡失败。";
            }


        }

        private void button3_Click(object sender, EventArgs e)
        {
            int status = 0;
            this.textBox3.Text = "";
            status = RCPClass.RCP11Class.StatusDemand(m_hCom);
            //
            switch (status)
            {
                case 0x00:
                    {
                        this.textBox3.Text = "机器正常待机";
                        break;
                    }
                case 0x02:
                    {
                        this.textBox3.Text = "卡片已到位，准备打印。";
                        break;
                    }
                case 0x04:
                    {
                        this.textBox3.Text = "机器准备进卡。";
                        break;
                    }
                case 0x11:
                    {
                        this.textBox3.Text = "机器上盖打开。";
                        break;
                    }

                case 0xff:
                    {
                        this.textBox3.Text = "机器正忙。";
                        break;
                    }

                default:
                    this.textBox3.Text = "机器获取不到。";
                    break;
            }
        }

        private void button20_Click(object sender, EventArgs e)
        {
            int status = 0;
            //单独擦卡指令
            status = RCPClass.RCP11Class.RCPCardOutputAuto(m_hCom);

            if (status == 0)
            {
                this.textBox3.Text = "卡片正在弹出。。。。。。";
            }
            else
            {
                this.textBox3.Text = "卡片弹出指令失败。";
            }
        }

        private void button19_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            int status = 0;

            //单独进卡指令
            status = RCPClass.RCP11Class.RCPCardInputAuto(m_hCom);

            if (status == 0)
            {
                this.textBox3.Text = "卡片正在进卡。。。。。。";
            }
            else
            {
                this.textBox3.Text = "卡片进卡指令失败。";
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            int status = 0;

            //弹卡指令
            status = RCPClass.RCP11Class.RCPCardOut(m_hCom);

            if (status == 0)
            {
                this.textBox3.Text = "卡片弹出中。。。。。。";
            }
            else
            {
                this.textBox3.Text = "卡片弹出指令失败。";
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            int status = 0;

            //单独擦卡指令
            status = RCPClass.RCP11Class.RCPCardSingleErase(m_hCom);

            if (status == 0)
            {
                this.textBox3.Text = "卡片正在擦除。。。。。。";
            }
            else
            {
                this.textBox3.Text = "卡片擦除指令失败。";
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            int status = 0;

            //机器清洗指令
            status = RCPClass.RCP11Class.RCPCleaningAuto(m_hCom);

            if (status == 0)
            {
                this.textBox3.Text = "机器正在清洗。。。。。。";
            }
            else
            {
                this.textBox3.Text = "卡片清洗指令失败。";
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            RCP.RCPClass.CB_CounterPrinteDemand callbackdatastruct;
            int status = 0;
            ulong temp1 = 0;
            status = RCPClass.RCP11Class.CounterPrinteDemand(m_hCom, out callbackdatastruct);
            string callbackdata = "";
            byte[] bytestr = new byte[1];

            temp1 = (ulong)(callbackdatastruct.CallBackData[3] & 0x000000ff);
            temp1 <<= 8;
            temp1 += (ulong)(callbackdatastruct.CallBackData[2] & 0x000000ff);
            temp1 <<= 8;
            temp1 += (ulong)(callbackdatastruct.CallBackData[1] & 0x000000ff);
            temp1 <<= 8;
            temp1 += (ulong)(callbackdatastruct.CallBackData[0] & 0x000000ff);


            if (status == 0)
            {
                callbackdata = "打印计数为：";
                //RCP反馈原始信息
                byte c = (byte)(temp1 / 1000000000);
                temp1 = (byte)(temp1 % 1000000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                c = (byte)(temp1 / 100000000);
                temp1 = (byte)(temp1 % 100000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 10000000);
                temp1 = (byte)(temp1 % 10000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 1000000);
                temp1 = (byte)(temp1 % 1000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 100000);
                temp1 = (byte)(temp1 % 100000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 10000);
                temp1 = (byte)(temp1 % 10000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 1000);
                temp1 = (byte)(temp1 % 1000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 100);
                temp1 = (byte)(temp1 % 100);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 10);
                temp1 = (byte)(temp1 % 10);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)temp1;
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);
                bytestr[0] = c;

                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                this.textBox3.Text = callbackdata;
            }
            else
            {
                this.textBox3.Text = "读总计数失败。";
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            RCP.RCPClass.CB_CounterCleaningDemand callbackdatastruct;
            int status = 0;
            ulong temp1;
            status = RCPClass.RCP11Class.CounterCleaningDemand(m_hCom, out callbackdatastruct);
            string callbackdata = "";
            byte[] bytestr = new byte[1];

            temp1 = (ulong)(callbackdatastruct.CallBackData[1] & 0x000000ff);
            temp1 <<= 8;
            temp1 += (ulong)(callbackdatastruct.CallBackData[0] & 0x000000ff);

            if (status == 0)
            {
                callbackdata = "清洗计数为：";

                //RCP反馈原始信息
                byte c = (byte)(temp1 / 10000);
                temp1 = (byte)(temp1 % 10000);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;

                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 1000);
                temp1 = (byte)(temp1 % 1000);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;

                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 100);
                temp1 = (byte)(temp1 % 100);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                c = (byte)(temp1 / 10);
                temp1 = (byte)(temp1 % 10);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);
                c = (byte)temp1;
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);
                this.textBox3.Text = callbackdata;
            }
            else
            {
                this.textBox3.Text = "读清总计数失败。";
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            RCP.RCPClass.CB_SerialnumberPrinteDemand callbackdatastruct;
            int status = 0;
            status = RCPClass.RCP11Class.SerialnumberPrinteDemand(m_hCom, out callbackdatastruct);
            string callbackdata = "";
            byte[] bytestr = new byte[1];
            ulong temp1 = 0;



            temp1 = (ulong)(callbackdatastruct.CallBackData[3] & 0x000000ff);
            temp1 <<= 8;
            temp1 += (ulong)(callbackdatastruct.CallBackData[2] & 0x000000ff);
            temp1 <<= 8;
            temp1 += (ulong)(callbackdatastruct.CallBackData[1] & 0x000000ff);
            temp1 <<= 8;
            temp1 += (ulong)(callbackdatastruct.CallBackData[0] & 0x000000ff);


            if (status == 0)
            {
                callbackdata = "序列号为：";

                //RCP反馈原始信息
                byte c = (byte)(temp1 / 1000000000);
                temp1 = (byte)(temp1 % 1000000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 100000000);
                temp1 = (byte)(temp1 % 100000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 10000000);
                temp1 = (byte)(temp1 % 10000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 1000000);
                temp1 = (byte)(temp1 % 1000000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 100000);
                temp1 = (byte)(temp1 % 100000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 10000);
                temp1 = (byte)(temp1 % 10000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 1000);
                temp1 = (byte)(temp1 % 1000);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 100);
                temp1 = (byte)(temp1 % 100);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                c = (byte)(temp1 / 10);
                temp1 = (byte)(temp1 % 10);
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                //MessageBox(m_strStatus);

                c = (byte)temp1;
                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                this.textBox3.Text = callbackdata;


            }
            else
            {
                this.textBox3.Text = "读取序列号失败。";
            }





        }

        private void button11_Click(object sender, EventArgs e)
        {
            this.richTextBox2.Text = "";
            RCP.RCPClass.CB_RfidCardRequestAndReadNum callbackdatastruct;
            int i;
            int status = 0;
            string callbackdata = "";
            byte[] bytestr = new byte[1];

            status = RCP.RCPClass.RCP11Class.RfidCardRequestAndReadNum(m_hCom, out callbackdatastruct);

            if (status == 0)
            {
                callbackdata = "卡片序列号为：";
                //RCP反馈原始信息
                for (i = 0; i < 4; i++) //将数组转换为Cstring型变量
                {
                    byte bt = callbackdatastruct.CallBackData[i]; //字符型

                    byte c = (byte)((bt >> 4) & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                    c = (byte)(bt & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr);


                    bytestr[0] = c;
                    callbackdata += " ";
                    this.richTextBox2.Text = callbackdata;

                }
            }
            else
            {
                this.richTextBox2.Text = "寻卡失败。";
            }
        }

        //private void button9_Click(object sender, EventArgs e)
        //{
        //    // TODO: Add your control notification handler code here
        //    RCP.RCPClass.CB_RefreshPrinterSetting callbackdatastruct;
        //    int status = 0;
        //    byte commandnum;
        //    byte[] bytestr = new byte[1];
        //    byte temp1;
        //    string callbackdata = "";
        //    //读取命令号
        //    if ("".Equals(this.textBox4.Text))
        //    {
        //        commandnum = (byte)0;
        //    }
        //    else
        //    {
        //        temp1 = (byte)int.Parse(this.textBox4.Text);
        //        commandnum = (byte)temp1;
        //    }

        //    if (commandnum != 0)
        //    {
        //        //读取命令内容
        //        status = RCP.RCPClass.RCP11Class.RefreshPrinterSetting(m_hCom, commandnum, out callbackdatastruct);

        //        if (status == 0)
        //        {
        //            temp1 = (byte)(commandnum & 0xff);

        //            callbackdata = "配置区：";

        //            //RCP反馈原始信息
        //            byte c = (byte)(temp1 / 100);
        //            temp1 = (byte)(temp1 % 100);

        //            if ((c >= 0) && (c <= 9))
        //                c = (byte)(c + 0x30);
        //            else
        //                c = (byte)(c + 0x37);


        //            bytestr[0] = c;
        //            callbackdata += System.Text.Encoding.Default.GetString(bytestr);


        //            c = (byte)(temp1 / 10);
        //            temp1 = (byte)(temp1 % 10);

        //            if ((c >= 0) && (c <= 9))
        //                c = (byte)(c + 0x30);
        //            else
        //                c = (byte)(c + 0x37);

        //            bytestr[0] = c;
        //            callbackdata += System.Text.Encoding.Default.GetString(bytestr);


        //            c = (byte)temp1;
        //            if ((c >= 0) && (c <= 9))
        //                c = (byte)(c + 0x30);
        //            else
        //                c = (byte)(c + 0x37);

        //            bytestr[0] = c;
        //            callbackdata += System.Text.Encoding.Default.GetString(bytestr);


        //            temp1 = (byte)(callbackdatastruct.CallBackData[0] & 0xff);

        //            callbackdata += "配置值为：";

        //            //RCP反馈原始信息
        //            c = (byte)(temp1 / 100);
        //            temp1 = (byte)(temp1 % 100);

        //            if ((c >= 0) && (c <= 9))
        //                c = (byte)(c + 0x30);
        //            else
        //                c = (byte)(c + 0x37);

        //            bytestr[0] = c;
        //            callbackdata += System.Text.Encoding.Default.GetString(bytestr);


        //            c = (byte)(temp1 / 10);
        //            temp1 = (byte)(temp1 % 10);

        //            if ((c >= 0) && (c <= 9))
        //                c = (byte)(c + 0x30);
        //            else
        //                c = (byte)(c + 0x37);

        //            bytestr[0] = c;
        //            callbackdata += System.Text.Encoding.Default.GetString(bytestr);


        //            c = (byte)temp1;
        //            if ((c >= 0) && (c <= 9))
        //                c = (byte)(c + 0x30);
        //            else
        //                c = (byte)(c + 0x37);

        //            bytestr[0] = c;
        //            callbackdata += System.Text.Encoding.Default.GetString(bytestr);

        //            this.richTextBox1.Text = callbackdata;

        //        }
        //        else
        //        {
        //            this.richTextBox1.Text = "读配置失败。";
        //        }
        //    }
        //    else
        //    {
        //        this.richTextBox1.Text = "命令区号不能为空。";
        //    }
        //}

        //private void button10_Click(object sender, EventArgs e)
        //{
        //    // TODO: Add your control notification handler code here
        //    int status = 0;
        //    byte commandnum;
        //    byte data;
        //    byte temp1;
        //    //读取命令号
        //    temp1 = (byte)(int.Parse(this.textBox4.Text));
        //    commandnum = (byte)temp1;

        //    //
        //    if (commandnum != 0)
        //    {
        //        //读取配置值
        //        temp1 = (byte)(int.Parse(this.textBox5.Text));
        //        data = (byte)temp1;

        //        //机器配置指令
        //        status = RCP.RCPClass.RCP11Class.SetPrinterSetting(m_hCom, commandnum, data);

        //        if (status == 0)
        //        {
        //            this.richTextBox1.Text = "机器配置正确。";
        //        }
        //        else
        //        {
        //            this.richTextBox1.Text = "机器配置失败。";
        //        }
        //    }
        //    else
        //    {
        //        this.richTextBox1.Text = "命令区号不能为空。";

        //    }
        //}

        private void button13_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            byte[] code = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0X7, 0X8, 0X9, 0XA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10 };
            byte blocknum = 1;
            byte keymodel = 0x00;
            byte[] key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };//CONTROL byte <FF 07 80 69>/<7F 07 88 69>
            int status = 0;

            status = RCP.RCPClass.RCP11Class.RfidCardRequestAndWriteData(m_hCom, blocknum, keymodel, key, code);

            if (status == 0)
            {
                this.richTextBox2.Text = "卡片数据写成功。";
            }
            else
            {
                this.richTextBox2.Text = "卡片数据写失败。";
            }
        }

        private void button23_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            // TODO: Add your control notification handler code here
            int status = 0;


            //设置进卡出卡模式指令
            status = RCP.RCPClass.RCP11Class.MagCardReadReady(m_hCom);


            if (status == 0)
            {
                this.richTextBox4.Text = "";
                this.richTextBox5.Text = "";
                this.richTextBox6.Text = "";

                this.label8.Text = "缓存已清除";
            }
            else
            {
                this.label8.Text = "机器配置失败。";
            }
        }

        private void button14_Click(object sender, EventArgs e)
        {
            this.richTextBox2.Text = "";
            byte[] code = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0Xff, 0X07, 0X80, 0X69, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
            byte area = 0;
            byte keynum = (byte)(area * 4 + 3);
            byte keymodel = (byte)0x00;
            byte[] key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };//CONTROL byte <FF 07 80 69>/<7F 07 88 69>
            int status = 0;
            status = RCP.RCPClass.RCP11Class.RfidCardRequestAndWriteData(m_hCom, keynum, keymodel, key, code);

            if (status == 0)
            {
                this.richTextBox2.Text = "A加密成功~!";
            }
            else
            {
                this.richTextBox2.Text = "A加密失败~!";
            }

        }

        private void button15_Click(object sender, EventArgs e)
        {
            this.richTextBox2.Text = "";
            // TODO: Add your control notification handler code here
            this.richTextBox2.Text = "";
            RCP.RCPClass.CB_RfidCardRequestAndReadData callbackdatastruct;
            byte area = 0;
            byte keynum = (byte)(area * 4 + 3);
            byte keymodel = 0x00;
            byte[] key = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 };
            int status = 0;
            byte[] bytestr = new byte[1];
            string callbackdata = "";

            //for(blocknum=0;blocknum<25;blocknum++)
            //{
            status = RCP.RCPClass.RCP11Class.RfidCardRequestAndReadData(m_hCom, keynum, keymodel, key, out callbackdatastruct);

            if (status == 0)
            {
                callbackdata = "块数据为：";

                byte bt = keynum; //字符型

                byte c = (byte)((bt >> 4) & 0x0F);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                c = (byte)(bt & 0x0F);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);
                callbackdata += " ";
                //UpdateData(FALSE); //更新编辑框内容
                //RCP反馈原始信息
                for (int i = 0; i < 16; i++) //将数组转换为Cstring型变量
                {
                    bt = (byte)(callbackdatastruct.CallBackData[i]); //字符型

                    c = (byte)((bt >> 4) & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                    c = (byte)(bt & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                    bytestr[0] = c;
                    callbackdata += " ";
                    //UpdateData(FALSE); //更新编辑框内容
                }
                this.richTextBox2.Text += callbackdata;
            }
            else
            {
                this.richTextBox2.Text = "读卡失败。";
            }
            //}
        }

        private void button16_Click(object sender, EventArgs e)
        {
            this.richTextBox2.Text = "";
            // TODO: Add your control notification handler code here
            byte[] code = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0X7f, 0X07, 0X88, 0X69, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 };
            byte area = 1;
            byte keynum = (byte)(area * 4 + 3);
            byte keymodel = (byte)0x01;
            byte[] key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };//CONTROL byte <FF 07 80 69>/<7F 07 88 69>
            int status = 0;

            status = RCP.RCPClass.RCP11Class.RfidCardRequestAndWriteData(m_hCom, keynum, keymodel, key, code);

            if (status == 0)
            {
                this.richTextBox2.Text = "B加密成功~!";
            }
            else
            {
                this.richTextBox2.Text = "B加密失败~!";
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            this.richTextBox2.Text = "";
            // TODO: Add your control notification handler code here
            RCP.RCPClass.CB_RfidCardRequestAndReadData callbackdatastruct;
            byte area = 1;
            byte keynum = (byte)(area * 4 + 3);
            byte keymodel = 0x01;
            byte[] key = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 };
            int status = 0;

            //for(blocknum=0;blocknum<25;blocknum++)
            //{
            byte[] bytestr = new byte[1];
            string callbackdata = "";

            //for(blocknum=0;blocknum<25;blocknum++)
            //{
            status = RCP.RCPClass.RCP11Class.RfidCardRequestAndReadData(m_hCom, keynum, keymodel, key, out callbackdatastruct);

            if (status == 0)
            {
                callbackdata = "块数据为：";

                byte bt = keynum; //字符型

                byte c = (byte)((bt >> 4) & 0x0F);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                c = (byte)(bt & 0x0F);

                if ((c >= 0) && (c <= 9))
                    c = (byte)(c + 0x30);
                else
                    c = (byte)(c + 0x37);

                bytestr[0] = c;
                callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                bytestr[0] = c;
                callbackdata += " ";
                //UpdateData(FALSE); //更新编辑框内容
                //RCP反馈原始信息
                for (int i = 0; i < 16; i++) //将数组转换为Cstring型变量
                {
                    bt = (byte)(callbackdatastruct.CallBackData[i]); //字符型

                    c = (byte)((bt >> 4) & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                    c = (byte)(bt & 0x0F);

                    if ((c >= 0) && (c <= 9))
                        c = (byte)(c + 0x30);
                    else
                        c = (byte)(c + 0x37);

                    bytestr[0] = c;
                    callbackdata += System.Text.Encoding.Default.GetString(bytestr);

                    bytestr[0] = c;
                    callbackdata += " ";
                    //UpdateData(FALSE); //更新编辑框内容
                }
            }
            else
            {
                this.richTextBox2.Text = "读卡失败。";
            }
        }

        private void button21_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            int i;
            byte c;
            int status = 0;
            byte[] code = new byte[250];

            int str_length;
            byte[] strtemp;
            byte[] str_buff=new byte[250];
            //读取编辑框字符串
            strtemp = System.Text.Encoding.Default.GetBytes(this.richTextBox4.Text.ToCharArray());


            //计算字符串字符数
            str_length = strtemp.Length;

            if (str_length > 76) str_length = 76;

            //
            for (i = 0; i < str_length; i++)
            {
                code[i] = (byte)strtemp[i];
            }

            for (i = 0; i < str_length; i++)
            {
                str_buff[i] = code[i];
            }

            for (i = str_length; i < 76; i++)
            {
               // c = (byte)0x00;
                //bytestr[0] = c;
                //str_buff += System.Text.Encoding.Default.GetString(bytestr);
                str_buff[i] = (byte)0x00;
            }

            //读取编辑框字符串
            strtemp = System.Text.Encoding.Default.GetBytes(this.richTextBox5.Text.ToCharArray());

            //计算字符串字符数
            str_length = strtemp.Length;

            if (str_length > 37) str_length = 37;

            //
            for (i = 0; i < str_length; i++)
            {
                code[i] = (byte)strtemp[i];
            }
            //str_buff_l = str_buff_l + str_length;
            for (i = 0; i < str_length; i++)
            {
                //bytestr[0] = code[i];
                //str_buff += System.Text.Encoding.Default.GetString(bytestr);
                str_buff[i + 76] = code[i];
            }

            //str_buff_l = str_buff_l + 37;
            for (i = str_length; i < 37; i++)
            {
                //c = (byte)0x00;
                //bytestr[0] = c;
                //str_buff += System.Text.Encoding.Default.GetString(bytestr);
                str_buff[i + 76] = (byte)0x00;
            }

            //读取编辑框字符串
            strtemp = System.Text.Encoding.Default.GetBytes(this.richTextBox6.Text.ToCharArray());

            //计算字符串字符数
            str_length = strtemp.Length;

            if (str_length > 104) str_length = 104;

            //
            for (i = 0; i < str_length; i++)
            {
                code[i] = (byte)strtemp[i];
            }
           // str_buff_l = str_buff_l + str_length;
            for (i = 0; i < str_length; i++)
            {
                //bytestr[0] = code[i];
                //str_buff += System.Text.Encoding.Default.GetString(bytestr);
                str_buff[i + 113] = code[i];
            }
            for (i = str_length; i < 104; i++)
            {
                //c = (byte)0x00;
               // bytestr[0] = c;
                //str_buff += System.Text.Encoding.Default.GetString(bytestr);
                str_buff[i + 113] = (byte)0x00;
            }

            //
            for (i = 0; i < 217; i++)
            {
                code[i] = (byte)str_buff[i];
            }

            //
            status = RCP.RCPClass.RCP11Class.MagCardWriteTrack_AllAuto(m_hCom, 0, code);

            if (status != 0)
            {
                MessageBox.Show("写卡失败");
            }
            this.richTextBox3.Text = System.Text.Encoding.Default.GetString(str_buff);

            // UpdateData(FALSE); //更新编辑框内容
        }

        private void button22_Click(object sender, EventArgs e)
        {
            RCP.RCPClass.CB_MagCardReadTrackIso callbackdatastruct;
            int i;
            int status = 0;

            byte c = 230;
            i = (byte)c;
            i += 4;

            this.richTextBox4.Text = "";
            this.richTextBox5.Text = "";
            this.richTextBox6.Text = "";

            //
            status = RCP.RCPClass.RCP11Class.MagCardReadTrackIso(m_hCom, out callbackdatastruct);
            byte[] bytestr = new byte[1];
            switch (status)
            {
                case 0x00:
                    {
                        //三轨全对
                        for (i = 0; i < 100; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack1+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容

                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);

                        }
                        //补齐数据
                        for (i = 76; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack2+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 137; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack3+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 304; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x01:
                    {
                        //二、三轨对
                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack2+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 137; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack3+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容

                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 304; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x02:
                    {
                        //一、三轨对
                        for (i = 0; i < 100; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack1+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 76; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack3+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 304; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x03:
                    {
                        //三轨对
                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack3+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 304; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x04:
                    {
                        //一、二轨对
                        for (i = 0; i < 100; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack1+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 76; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack2+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 137; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x05:
                    {
                        //二轨对
                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack2+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容

                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 137; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x06:
                    {
                        //一轨对
                        for (i = 0; i < 100; i++) //将数组转换为Cstring型变量 
                        {
                            //strtemp.Format("%c",code[i]); //将字符送入临时变量strtemp存放
                            //m_strtrack1+=strtemp; //加入接收编辑框对应字符串 
                            //UpdateData(FALSE); //更新编辑框内容
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 76; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                default:
                    {
                        //m_strtrack1="读卡失败。";
                        //UpdateData(FALSE); //更新编辑框内容
                        this.richTextBox4.Text = "读卡失败";
                    }

                    break;
            }
        }

        private void button24_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            RCP.RCPClass.CB_MagCardReadTrackIsoORJis callbackdatastruct;
            int i;
            int status = 0;
            byte c = 230;
            i = (byte)c;
            i += 4;
            //
            status = RCP.RCPClass.RCP11Class.MagCardReadTrackIsoORJis(m_hCom, out callbackdatastruct);
            byte[] bytestr = new byte[1];

            this.richTextBox4.Text = "";
            this.richTextBox5.Text = "";
            this.richTextBox6.Text = "";

            if (status < 0x07)
            {
                //RCP反馈原始信息
                for (i = 0; i < 100; i++) //将数组转换为Cstring型变量 
                {
                    bytestr[0] = callbackdatastruct.CallBackData[i];
                    this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                }
                //RCP反馈原始信息
                for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                {
                    bytestr[0] = callbackdatastruct.CallBackData[i];
                    this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                }
                //RCP反馈原始信息
                for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                {
                    bytestr[0] = callbackdatastruct.CallBackData[i];
                    this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                }
            }
            else
            {

                this.richTextBox4.Text = "读卡失败。";
            }
        }

        private void button25_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            int i;
            int status = 0;
            byte c;
            byte[] code = new byte[250];

            int str_length;
            byte[] strtemp;
            byte[] str_buff=new byte[250];

            //读取编辑框字符串
            strtemp = System.Text.Encoding.Default.GetBytes(this.richTextBox4.Text.ToCharArray());

            //计算字符串字符数
            str_length = strtemp.Length;

            if (str_length > 69) str_length = 69;

            //
            for (i = 0; i < str_length; i++)
            {
                code[i] = (byte)strtemp[i];
            }

            for (i = 0; i < str_length; i++)
            {
                //str_buff += code[i];
                str_buff[i] = code[i];
            }

            for (i = str_length; i < 69; i++)
            {
               // c = 0x00;
                //str_buff += c;

                str_buff[i] = 0x00;
            }

            //读取编辑框字符串
            strtemp = System.Text.Encoding.Default.GetBytes(this.richTextBox5.Text.ToCharArray());

            //计算字符串字符数
            str_length = strtemp.Length;

            if (str_length > 69) str_length = 69;

            //
            for (i = 0; i < str_length; i++)
            {
                code[i] = (byte)strtemp[i];
            }

            for (i = 0; i < str_length; i++)
            {
                str_buff[69+i]= code[i];
            }

            for (i = str_length; i < 69; i++)
            {
                //c = 0x00;
               // str_buff += c;
                str_buff[69 + i] = (byte)0x00;
            }

            //读取编辑框字符串
            strtemp = System.Text.Encoding.Default.GetBytes(this.richTextBox6.Text.ToCharArray());

            //计算字符串字符数
            str_length = strtemp.Length;

            if (str_length > 69) str_length = 69;

            //
            for (i = 0; i < str_length; i++)
            {
                code[i] = (byte)strtemp[i];
            }

            for (i = 0; i < str_length; i++)
            {
                str_buff[138+i]= code[i];
            }

            for (i = str_length; i < 69; i++)
            {
                //c = 0x00;
               // str_buff += c;
                str_buff[138 + i] = (byte)0x00;
            }

            //
            for (i = 0; i < 207; i++)
            {
                code[i] = (byte)str_buff[i];
            }

            //
            status = RCP.RCPClass.RCP11Class.MagCardWriteTrack_AllAuto(m_hCom, 1, code);

            if (status != 0)
            {
                MessageBox.Show("写卡失败");
            }

            this.richTextBox3.Text = System.Text.Encoding.Default.GetString(str_buff);

            // UpdateData(FALSE); //更新编辑框内容

        }

        private void button26_Click(object sender, EventArgs e)
        {
            // TODO: Add your control notification handler code here
            RCPClass.CB_MagCardReadTrackJis callbackdatastruct;
            int i;
            int status = 0;


            byte c = 230;
            i = (byte)c;
            i += 4;

            this.richTextBox4.Text = "";
            this.richTextBox5.Text = "";
            this.richTextBox6.Text = "";


            //
            status = RCPClass.RCP11Class.MagCardReadTrackJis(m_hCom, out callbackdatastruct);
            byte[] bytestr = new byte[1];
            switch (status)
            {
                case 0x00:
                    {
                        //三轨全对
                        for (i = 0; i < 100; i++)
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 69; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 169; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 269; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x01:
                    {
                        //二、三轨对
                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 169; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 269; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x02:
                    {
                        //一、三轨对
                        for (i = 0; i < 100; i++)
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 69; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 269; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x03:
                    {
                        //三轨对
                        for (i = 200; i < 350; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox6.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 269; i < 350; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x04:
                    {
                        //一、二轨对
                        for (i = 0; i < 100; i++)
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 69; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 169; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x05:
                    {
                        //二轨全对
                        for (i = 100; i < 200; i++) //将数组转换为Cstring型变量 
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox5.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 169; i < 200; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                case 0x06:
                    {
                        //一轨全对
                        for (i = 0; i < 100; i++)
                        {
                            bytestr[0] = callbackdatastruct.CallBackData[i];
                            this.richTextBox4.Text += System.Text.Encoding.Default.GetString(bytestr);
                        }
                        //补齐数据
                        for (i = 69; i < 100; i++)
                        {
                            callbackdatastruct.CallBackData[i] = 0x00;
                        }

                        break;
                    }

                default:
                    {
                        this.richTextBox4.Text = "读卡失败。";
                    }
                    break;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            string m_str = this.content_tb.Text;

            byte[] printer = System.Text.Encoding.Default.GetBytes("NPPrinter1.1");
            byte[] strText = System.Text.Encoding.Default.GetBytes(m_str);
            byte[] fontname = System.Text.Encoding.Default.GetBytes(this.font_tb.Text);
            int x = int.Parse(this.x_tb.Text);
            int y = int.Parse(this.y_tb.Text);
            int direction = 0;
            if (this.radioButton1.Checked)
            {
                direction = int.Parse(radioButton1.Tag.ToString());
            }
            if (this.radioButton2.Checked)
            {
                direction = int.Parse(radioButton2.Tag.ToString());
            }
            int fontsize = int.Parse(this.fontsize_tb.Text);
            int ret = RCPClass.RCP11Class.PrintStr(printer, strText, x, y, direction, fontname, fontsize);
            if (ret == 0)
            {
                MessageBox.Show("打印成功");
            }
            else
            {
                MessageBox.Show("打印失败");
            }
        }
    }
}
